package com.example.szh.mvp.presenter;

import com.blankj.utilcode.util.LogUtils;
import com.example.szh.db.DBManager;
import com.example.szh.entity.BaseEntity;
import com.example.szh.entity.LoginEntity;
import com.example.szh.entity.UserEntity;
import com.example.szh.mvp.contract.LoginContract;
import com.example.szh.nextwork.presenter.BasePresenter;
import com.example.szh.utils.ToastUtils;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.schedulers.Schedulers;

public class LoginPresenter extends BasePresenter<LoginContract.ILoginModel,LoginContract.ILoginView> {
    @Inject
    public LoginPresenter(LoginContract.ILoginModel iLoginModel, LoginContract.ILoginView iLoginView) {
        super(iLoginModel, iLoginView);
    }

    //声明对应请求方法
    public void requestLogin(Long phone, String pwd, int logincode){
        if (pwd.isEmpty()){
            ToastUtils.showMsg("密码不能为空");
            return;
        }
        Map<String,Object> map=new HashMap<>();
        map.put("phone", phone);
        map.put("pwd", pwd);
        map.put("code", logincode);
        m.request(map).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }

    @Override
    public void onNext(@NonNull BaseEntity baseEntity) {

        v.refresh(baseEntity);
    }
}
